************************************************************
************************************************************
**																			    **
**	Tanzania - Importing CPI data				  				**
**										   				  						**
**										   				  						**
************************************************************
************************************************************

clear
version 14
set more off
cap log close

gl IN 	"${LOCDRIVE}\Parameters"
gl TEMP	"${LOCDRIVE}\Tempdata"

log using "${TEMP}\CPI_Tanzania", replace

foreach year in 2008 2009 2010 2011 2012 2013 {
	import excel using "${IN}\CPI_Summary_Referenced_2009-2017.xls", clear sheet("`year'") cellrange(A2:O15) firstrow

	sxpose, clear force
	
	replace _var13 = "tot" in 1
	replace _var13 = "All items index" in 2
	foreach var of varlist _all {
		loc varname = `var' in 1
		loc varname "SN_`varname'"
		loc varlabel = `var' in 2
		la var `var' "`varlabel'"
		rename `var' `varname'
		loc weight = `varname' in 3
		g `varname'_wt = `weight'
		}
	
	drop in 1/3
	
	g year = `year'
	g month = _n
	/*"month"
	forvalues i = 1/12 {
		if `i' < 10 {
			loc m = "0`i'"
			}
			else if `i' >= 10 {
				loc m = "`i'"
				}
		loc j = `i' + 1
		replace month = "`m'" in `j'
		}*/
	
	tempfile cpi_`year'
	save `cpi_`year'', replace
	}
	
use `cpi_2008', clear
forvalues year = 2009/2013  {
	sort year month
	append using `cpi_`year''	
	}
	
forvalues i = 1/12 {
	g tempvar = real(SN_`i')
	drop SN_`i'
	rename tempvar SN_`i'
	}
	
order year month SN_1 SN_1_wt SN_2 SN_2_wt SN_3 SN_3_wt SN_4 SN_4_wt SN_5 SN_5_wt SN_6 SN_6_wt SN_7 SN_7_wt SN_8 SN_8_wt SN_9 SN_9_wt SN_10 SN_10_wt SN_11 SN_11_wt SN_12 SN_12_wt SN_tot SN_tot_wt
sort year month

save "${TEMP}\CPI_Tanzania_Allyears", replace


********
log close
